package com.glsc.ngateway.opmanage.controller.ledger;


import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.Role;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.User;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.ItDict;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.it.ItDictData;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.ledger.*;
import com.glsc.ngateway.opmanage.aspect.UserCache;
import com.glsc.ngateway.opmanage.dto.*;
import com.glsc.ngateway.opmanage.service.DictionaryService;
import com.glsc.ngateway.opmanage.service.MailService;
import com.glsc.ngateway.opmanage.service.ledger.LedgerAuthService;
import com.glsc.ngateway.opmanage.service.ledger.LedgerService;
import com.glsc.ngateway.opmanage.utils.DateUtils;
import com.glsc.ngateway.opmanage.utils.SpecificationFactory;
import com.glsc.ngateway.opmanage.utils.report.ReportFileConfigEnum;
import com.glsc.ngateway.opmanage.utils.report.ReportFileUtil;
import com.google.common.collect.Lists;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 自定义台账
 */
@RestController
@RequestMapping("/api/ledger")
@Slf4j
public class LedgerController {

    @Resource
    private UserCache userCache;

    @Resource
    private LedgerService ledgerService;

    @Resource
    private DictionaryService dictionaryService;

    @Autowired
    private MailService mailService;

    @Resource
    private LedgerAuthService ledgerAuthService;


    /**
     * 分页查询个人台账模板列表
     *
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("/template/page")
    public PlatformResponse<Page<LedgerTemplate>> pageTemplate(@RequestBody LedgerTemplateDto dto, HttpServletRequest request) {

        Map<String, Object> param = new HashMap<>();
        if (StringUtils.isNotBlank(dto.getName())) {
            param.put("LIKE_name", dto.getName());
        }

        //User user = userCache.get(request);
        //param.put("EQ_userId", user.getId());
        User user = userCache.get(request);
        Set<Role> roleSet = user.getRoles();
        if (CollectionUtils.isEmpty(roleSet)) {
            return PlatformResponse.failedMsg("请登录");
        }
        Set<String> roleNameSet = roleSet.stream().map(Role::getName).collect(Collectors.toSet());

        if (!roleNameSet.contains("LEDGER_ALL_ADMIN")) {
            List<LedgerAuthTemplate> templates = ledgerAuthService.findByUserId(user.getUsername());
            if (CollectionUtils.isEmpty(templates)) {
                return PlatformResponse.successData(Page.empty());
            }

            Set<Integer> tempalteIdSet = templates.stream().map(LedgerAuthTemplate::getLedgerTemplateId).collect(Collectors.toSet());
            if (CollectionUtils.isNotEmpty(tempalteIdSet)) {
                param.put("IN_id", StringUtils.join(templates.stream().map(LedgerAuthTemplate::getLedgerTemplateId).collect(Collectors.toSet()), ","));

            } else {
                return PlatformResponse.successData(Page.empty());
            }
        }


        Page<LedgerTemplate> page = ledgerService.findLedgerTemplatePage(dto.getPageNo(), dto.getPageSize(), param);

        return PlatformResponse.successData(page);
    }

    /**
     * 查询所有台账模板-在台账权限模板配置使用，要真实的查询出所有的台账模板
     *
     * @param
     * @param request
     * @return
     */
    @GetMapping("/template/list/all")
    public PlatformResponse<List<LedgerTemplate>> listAllTemplate1(HttpServletRequest request) {

        Map<String, Object> param = new HashMap<>();

        Page<LedgerTemplate> page = ledgerService.findLedgerTemplatePage(1, 1000, param);

        if (Objects.isNull(page) || Objects.isNull(page.getContent())) {
            return PlatformResponse.successData(Lists.newArrayList());
        }

        return PlatformResponse.successData(page.getContent());
    }

    /**
     * 根据id查找台账模板以及任务模板信息
     *
     * @param
     * @return
     */
    @GetMapping("/template/info")
    public PlatformResponse<LedgerTemplate> findTemplateById(@ApiParam(required = false, value = "id") @RequestParam(required = true) Integer id) {

        LedgerTemplate template = ledgerService.findLedgerTemplateById(id);
        List<LedgerTaskTemplate> ledgerTaskTemplates = ledgerService.listTemplateByLedgerTemplateId(template.getId());
        if (CollectionUtils.isNotEmpty(ledgerTaskTemplates)) {
            ledgerTaskTemplates = ledgerTaskTemplates.stream().sorted(Comparator.comparing(LedgerTaskTemplate::getTaskSort)).collect(Collectors.toList());
        }
        template.setTaskTemplateList(ledgerTaskTemplates);
        return PlatformResponse.successData(template);
    }

    /**
     * 保存台账模板信息
     *
     * @param template
     * @return
     */
    @PostMapping("/template/save")
    public PlatformResponse<?> saveTemplate(@RequestBody LedgerTemplate template) {
        ledgerService.saveLedgerTemplate(template);
        return PlatformResponse.success();
    }

    /**
     * 删除台账模板信息
     *
     * @param template
     * @return
     */
    @PostMapping("/template/delete")
    public PlatformResponse<?> deleteTemplate(@RequestBody LedgerTemplate template) {
        ledgerService.deleteTempLateById(template.getId());
        return PlatformResponse.success();
    }

    /**
     * 查询所有的台账模板信息-用于下拉列表
     *
     * @return
     */
    @GetMapping("/template/all")
    public PlatformResponse<List<LedgerTemplate>> listAllTemplate(HttpServletRequest request) {
        List<LedgerTemplate> ledgerTemplates = ledgerService.listAllTemplate();
        if (CollectionUtils.isEmpty(ledgerTemplates)) {
            return PlatformResponse.successData(Lists.newArrayList());
        }

        User user = userCache.get(request);
        Set<Role> roleSet = user.getRoles();
        if (CollectionUtils.isEmpty(roleSet)) {
            return PlatformResponse.successData(Lists.newArrayList());
        }
        Set<String> roleNameSet = roleSet.stream().map(Role::getName).collect(Collectors.toSet());

        if (!roleNameSet.contains("LEDGER_ALL_ADMIN")) {
            List<LedgerAuthTemplate> templates = ledgerAuthService.findByUserId(user.getUsername());
            if (CollectionUtils.isEmpty(templates)) {
                return PlatformResponse.successData(Lists.newArrayList());
            }

            Set<Integer> tempalteIdSet = templates.stream().map(LedgerAuthTemplate::getLedgerTemplateId).collect(Collectors.toSet());
            List<LedgerTemplate> resList = ledgerTemplates.stream().filter(e -> tempalteIdSet.contains(e.getId())).collect(Collectors.toList());
            if (CollectionUtils.isEmpty(resList)) {
                return PlatformResponse.successData(Lists.newArrayList());
            }

            return PlatformResponse.successData(resList);
        }


        return PlatformResponse.successData(ledgerTemplates);
    }


    /**
     * 分页查询台账列表
     *
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("/page")
    public PlatformResponse<Page<BusinessLedger>> page(@RequestBody LedgerTemplateDto dto, HttpServletRequest request) {

        Map<String, Object> param = new HashMap<>();
        if (StringUtils.isNotBlank(dto.getName())) {
            param.put("LIKE_name", dto.getName());
        }
        if (StringUtils.isNotBlank(dto.getStatus())) {
            param.put("EQ_status", dto.getStatus());
        }

        if (StringUtils.isNotBlank(dto.getTemplateName())) {
            param.put("EQ_templateName", dto.getTemplateName());
        }

        User user = userCache.get(request);
        Set<Role> roleSet = user.getRoles();
        if (CollectionUtils.isEmpty(roleSet)) {
            return PlatformResponse.successData(Page.empty());
        }

        Set<String> roleNameSet = roleSet.stream().map(Role::getName).collect(Collectors.toSet());
        if (!roleNameSet.contains("LEDGER_ALL_ADMIN")) {
            List<LedgerAuthTemplate> templates = ledgerAuthService.findByUserId(user.getUsername());
            if (CollectionUtils.isEmpty(templates)) {
                return PlatformResponse.successData(Page.empty());
            }
            param.put("IN_ledgerTemplateId", StringUtils.join(templates.stream().map(LedgerAuthTemplate::getLedgerTemplateId).collect(Collectors.toSet()), ","));
        }

        Page<BusinessLedger> page = ledgerService.findLedgerPage(dto.getPageNo(), dto.getPageSize(), param);
        return PlatformResponse.successData(page);
    }


    /**
     * 根据id查找台账信息
     *
     * @param id
     * @return
     */
    @GetMapping("/info")
    public PlatformResponse<BusinessLedger> findLedgerById(@ApiParam(value = "id") @RequestParam(required = true) Integer id, HttpServletRequest request) {

        User user = userCache.get(request);
        Set<Role> roleSet = user.getRoles();
        if (CollectionUtils.isEmpty(roleSet)) {
            return PlatformResponse.failedMsg("无权限");
        }

        Set<String> roleNameSet = roleSet.stream().map(Role::getName).collect(Collectors.toSet());

        BusinessLedger ledger = ledgerService.findLedgerById(id);
        if (!roleNameSet.contains("LEDGER_ALL_ADMIN")) {
            List<LedgerAuthTemplate> templates = ledgerAuthService.findByUserId(user.getUsername());
            if (CollectionUtils.isEmpty(templates)) {
                return PlatformResponse.failedMsg("无权限");
            }

            Set<Integer> templateIdSet = templates.stream().map(LedgerAuthTemplate::getLedgerTemplateId).collect(Collectors.toSet());
            if (!templateIdSet.contains(ledger.getLedgerTemplateId())) {
                return PlatformResponse.failedMsg("无权限");
            }
        }
        return PlatformResponse.successData(ledger);
    }

    /**
     * 根据完成人id查询今日此人完成的台账任务列表
     *
     * @param finishId
     * @return
     */
    @GetMapping("/findTodayFinishLedgerByFinishId")
    public PlatformResponse<List<BusinessLedger>> findTodayFinishLedgerByFinishId(@ApiParam(value = "finishId") @RequestParam(required = true) Long finishId) {
        List<BusinessLedger> ledgers = ledgerService.findTodayFinishLedgerByFinishId(finishId);
        if (CollectionUtils.isEmpty(ledgers)) {
            return PlatformResponse.successData(Lists.newArrayList());
        }
        return PlatformResponse.successData(ledgers);
    }

    /**
     * 根据台账id查找所有已完成的任务
     *
     * @param id
     * @return
     */
    @GetMapping("/task/finishList")
    public PlatformResponse<List<BusinessLedgerTask>> finishList(@ApiParam(value = "id") @RequestParam(required = true) Integer id) {
        List<BusinessLedgerTask> tasks = ledgerService.listLedgerByLedgerId(id);
        if (CollectionUtils.isEmpty(tasks)) {
            return PlatformResponse.successData(Lists.newArrayList());
        }

        tasks = tasks.stream().filter(e -> "1".equals(e.getStatus())).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(tasks)) {
            return PlatformResponse.successData(Lists.newArrayList());
        }
        return PlatformResponse.successData(tasks);
    }


    /**
     * 创建台账任务信息
     *
     * @param ledger
     * @return
     */
    @PostMapping("/create")
    public PlatformResponse<?> createLedger(@RequestBody BusinessLedger ledger, HttpServletRequest request) {
        User user = userCache.get(request);
        ledgerService.createLedger(ledger, user);
        return PlatformResponse.success();
    }

    /**
     * 修改台账主体内容
     *
     * @param ledger
     * @return
     */
    @PostMapping("/save")
    public PlatformResponse<?> saveLedger(@RequestBody BusinessLedger ledger) {
        ledgerService.saveBusinessLedger(ledger);
        return PlatformResponse.success();
    }

    /**
     * 手动将台账状态修改为完成
     *
     * @param dto
     * @return
     */
    @PostMapping("/finish")
    public PlatformResponse<BusinessLedger> finishLedger(@RequestBody BusinessLedger dto, HttpServletRequest request) {
        BusinessLedger ledger = ledgerService.findLedgerById(dto.getId());
        ledger.setStatus("1");
        ledger.setFinishTime(DateUtils.getNowDateString());
        User user = userCache.get(request);
        ledger.setFinishId(user.getId());
        ledger.setFinishUserName(user.getName());
        ledgerService.saveBusinessLedger(ledger);
        return PlatformResponse.successData(ledger);
    }

    /**
     * 完成一条台账任务
     *
     * @param task
     * @param request
     * @return
     */
    @PostMapping("/finish/task")
    public PlatformResponse<?> finishLedger(@RequestBody BusinessLedgerTask task, HttpServletRequest request) {
        User user = userCache.get(request);
        ledgerService.finishLedgerTask(task, user);
        return PlatformResponse.success();
    }


    /**
     * 分页查询台账任务文件模板
     *
     * @param dto
     * @param request
     * @return
     */
    @PostMapping("/template/file/page")
    public PlatformResponse<Page<LedgerTaskFileTemplate>> pageLedgerTaskFileTemplate(@RequestBody LedgerFileTemplateDto dto, HttpServletRequest request) {

        Map<String, Object> param = new HashMap<>();
        if (StringUtils.isNotBlank(dto.getFileName())) {
            param.put("LIKE_fileName", dto.getFileName());
        }
        if (StringUtils.isNotBlank(dto.getWorkItemType())) {
            param.put("LIKE_workItemType", dto.getWorkItemType());
        }

        Page<LedgerTaskFileTemplate> page = ledgerService.findLedgerTaskFileTemplatePage(dto.getPageNo(), dto.getPageSize(), param);

        return PlatformResponse.successData(page);
    }

    /**
     * 保存台账任务文件模板
     *
     * @param template
     * @return
     */
    @PostMapping("/template/file/save")
    public PlatformResponse<?> saveLedgerTaskFileTemplate(@RequestBody LedgerTaskFileTemplate template) {
        ledgerService.saveLedgerTaskFileTemplate(template);
        return PlatformResponse.success();
    }

    /**
     * 删除台账任务文件模板
     *
     * @param template
     * @return
     */
    @PostMapping("/template/file/delete")
    public PlatformResponse<?> deleteTemplate(@RequestBody LedgerTaskFileTemplate template) {
        ledgerService.deleteLedgerTaskFileTemplate(template.getId());
        return PlatformResponse.success();
    }

    /**
     * 签收一条台账任务文件
     *
     * @param file
     * @return
     */
    @PostMapping("/task/file/finish")
    public PlatformResponse<?> finishFile(@RequestBody BusinessLedgerTaskFile file, HttpServletRequest request) {
        User user = userCache.get(request);
        ledgerService.finishFile(file.getId(), file.getWorkValue(), file.getMemo(), user);
        return PlatformResponse.success();
    }

    /**
     * 台账文件更新按钮
     *
     * @param file
     * @param request
     * @return
     */
    @PostMapping("/task/file/update")
    public PlatformResponse<?> updateFile(@RequestBody BusinessLedgerTaskFile file, HttpServletRequest request) {
        User user = userCache.get(request);
        ledgerService.updateFile(file.getId(), file.getWorkValue(), file.getMemo(), user);
        return PlatformResponse.success();
    }


    /**
     * 获取任务详情和它关联的文件列表
     *
     * @param id
     * @return
     */
    @GetMapping("/task/info")
    public PlatformResponse<BusinessLedgerTask> findTaskById(@ApiParam(value = "id") @RequestParam(required = true) Integer id) {
        BusinessLedgerTask task = ledgerService.findTaskById(id);
        return PlatformResponse.successData(task);
    }

    /**
     * 更新工作值
     *
     * @param task
     * @param request
     * @return
     */
    @PostMapping("/task/updateWorkValue")
    public PlatformResponse<?> updateWorkValue(@RequestBody BusinessLedgerTask task, HttpServletRequest request) {
        User user = userCache.get(request);
        ledgerService.updateWorkValue(task, user);
        return PlatformResponse.success();
    }


    /**
     * key&sac 台账文件清单导出
     *
     * @param ledgerId
     * @param response
     * @return
     * @throws IOException
     */
    @PostMapping("/export")
    public byte[] export(@ApiParam(value = "台账id") @RequestParam(required = false) Integer ledgerId, HttpServletResponse response) throws IOException {

        //response.setHeader("Content-Disposition", "attachment;" + "filename=" + URLEncoder.encode(ReportFileConfigEnum.LEDGER_FILE_EXPORT.getFileName(), "UTF-8"));
        response.setContentType("application/octet-stream");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");

        List<LedgerFileExportDto> resList = Lists.newArrayList();
        BusinessLedger ledger = ledgerService.findLedgerById(ledgerId);
        List<BusinessLedgerTaskFile> dataList = Lists.newArrayList();


        if (CollectionUtils.isNotEmpty(ledger.getTaskList())) {
            for (BusinessLedgerTask ledgerTask : ledger.getTaskList()) {
                if ("kyc_sac_org".equals(ledgerTask.getWorkItemType()) || "kyc_sac_prod".equals(ledgerTask.getWorkItemType())) {
                    BusinessLedgerTask task = ledgerService.findTaskById(ledgerTask.getId());
                    if (CollectionUtils.isNotEmpty(task.getFileList())) {
                        dataList.addAll(task.getFileList());
                    }
                }
            }
        }

        Map<String, String> fileTypeMap = new HashMap<>();
        ItDictData dictData = dictionaryService.findByDictData("t_ledger_file_type");
        if (Objects.nonNull(dictData)) {
            if (CollectionUtils.isNotEmpty(dictData.getDictValues())) {
                for (ItDict dictValue : dictData.getDictValues()) {
                    fileTypeMap.put(dictValue.getDictSubentry(), dictValue.getDictValue());
                }
            }
        }

        String customerNo = ledger.getTaskList().get(0).getWorkValue();
        if (CollectionUtils.isNotEmpty(dataList)) {
            for (BusinessLedgerTaskFile file : dataList) {
                resList.add(LedgerFileExportDto.builder().name(ledger.getName()).customerNo(customerNo).fileName(file.getFileName()).type(fileTypeMap.get(file.getType()))
                        .workValue(file.getWorkValue()).remark(file.getMemo()).build());
            }
        }
        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(ledger.getName() + "-" + customerNo + "-文件清单.xlsx", "UTF-8"));

        return ReportFileUtil.export(resList, ReportFileConfigEnum.LEDGER_FILE_EXPORT);
    }


    /**
     * 分页查询台账列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/material/page")
    public PlatformResponse<Page<LedgerFileExportDto>> pageMaterial(@RequestBody LedgerMaterialDto dto) {
        Specification spec = getSpecification(dto);

        Page<BusinessLedgerTaskFile> page = ledgerService.findLedgerFilePageBySpec(dto.getPageNo(), dto.getPageSize(), spec);

        List<Integer> taskIdList = page.stream().map(BusinessLedgerTaskFile::getBusinessLedgerTaskId).collect(Collectors.toList());

        List<BusinessLedgerTask> businessLedgerTaskList = ledgerService.listLedgerById(taskIdList);

        Map<Integer, BusinessLedger> map = new HashMap<>();
        businessLedgerTaskList.forEach(businessLedgerTask -> {
            map.put(businessLedgerTask.getId(), ledgerService.findLedgerById(businessLedgerTask.getLedgerId()));
        });

        Map<String, String> fileTypeMap = new HashMap<>();
        ItDictData dictData = dictionaryService.findByDictData("t_ledger_file_type");
        if (Objects.nonNull(dictData)) {
            if (CollectionUtils.isNotEmpty(dictData.getDictValues())) {
                for (ItDict dictValue : dictData.getDictValues()) {
                    fileTypeMap.put(dictValue.getDictSubentry(), dictValue.getDictValue());
                }
            }
        }
        Page<LedgerFileExportDto> newPage = page.map(file -> {
            BusinessLedger ledger = map.get(file.getBusinessLedgerTaskId());
            String customerNo = ledger.getTaskList().get(0).getWorkValue();
            return LedgerFileExportDto.builder().name(ledger.getName()).customerNo(customerNo).fileName(file.getFileName()).type(fileTypeMap.get(file.getType()))
                    .workValue(file.getWorkValue()).createTime(file.getCreateTime()).remark(file.getMemo()).fileActualReceive(file.getFileActualReceive()).build();
        });

        return PlatformResponse.successData(newPage);
    }

    private Specification getSpecification(LedgerMaterialDto dto) {
        LocalDateTime startTime = null;
        LocalDateTime endTime = null;
        if (StringUtils.isNotBlank(dto.getStartTime())) {
            LocalDate localDate = DateUtils.string2LocalDate(dto.getStartTime(), DateUtils.formatDate_);
            startTime = localDate.atStartOfDay();
        }

        if (StringUtils.isNotBlank(dto.getEndTime())) {
            LocalDate localDate = DateUtils.string2LocalDate(dto.getEndTime(), DateUtils.formatDate_);
            endTime = localDate.atTime(23, 59, 59);
        }
        SpecificationFactory.SpecElement fileTemplateIdE = SpecificationFactory.initSpecElement(SpecificationFactory.Type.LIKE, "fileName", dto.getFileName());
        SpecificationFactory.SpecElement startTimeE = SpecificationFactory.initSpecElement(SpecificationFactory.Type.GE, "createTime", startTime);
        SpecificationFactory.SpecElement endTimeE = SpecificationFactory.initSpecElement(SpecificationFactory.Type.LE, "createTime", endTime);

        Specification spec = SpecificationFactory.build(SpecificationFactory.OP.AND, fileTemplateIdE, startTimeE, endTimeE);
        return spec;
    }


    /**
     * 导出材料列表
     *
     * @param dto
     * @param response
     * @return
     */
    @PostMapping("/material/export")
    public byte[] exportMaterial(@RequestBody LedgerMaterialDto dto, HttpServletResponse response) throws IOException {
        response.setContentType("application/octet-stream");
        response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");

        dto.setPageNo(1);
        dto.setPageSize(10000);
        PlatformResponse<Page<LedgerFileExportDto>> pagePlatformResponse = pageMaterial(dto);
        List<LedgerFileExportDto> exportDtoList = Lists.newArrayList();
        if (Objects.nonNull(pagePlatformResponse) && Objects.nonNull(pagePlatformResponse.getData()) && CollectionUtils.isNotEmpty(pagePlatformResponse.getData().getContent())) {
            exportDtoList = pagePlatformResponse.getData().getContent();
        }

        response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("客户材料清单-" + DateUtils.getNowDateString() + ".xlsx", "UTF-8"));

        return ReportFileUtil.export(exportDtoList, ReportFileConfigEnum.LEDGER_FILE_EXPORT);
    }

    /**
     * 经办完成
     *
     * @param task
     * @param request
     * @return
     */
    @PostMapping("/finish/handleFinish")
    public PlatformResponse<?> handleFinish(@RequestBody BusinessLedgerTask task, HttpServletRequest request) {
        User user = userCache.get(request);
        BusinessLedgerTask finishTask = ledgerService.findTaskById(task.getId());
        finishTask.setHandleId(user.getId());
        finishTask.setHandleUserName(user.getName());
        return PlatformResponse.success();
    }

    /**
     * 复核完成
     *
     * @param task
     * @param request
     * @return
     */
    @PostMapping("/finish/checkFinish")
    public PlatformResponse<?> checkFinish(@RequestBody BusinessLedgerTask task, HttpServletRequest request) {
        User user = userCache.get(request);
        BusinessLedgerTask finishTask = ledgerService.findTaskById(task.getId());
        finishTask.setCheckId(user.getId());
        finishTask.setCheckUserName(user.getName());
        return PlatformResponse.success();
    }


    // /**
    //  * 发送邮件
    //  *
    //  * @param dto
    //  * @param request
    //  * @return
    //  */
    // @PostMapping("/material/send")
    // public PlatformResponse<Page<LedgerFileExportDto>> sendMaterial(@RequestBody LedgerMaterialDto dto, HttpServletRequest request) throws IOException {
    //     List<LedgerFileExportDto> exportDtoList = this.getLedgerFileExportDtoList(dto);
    //     byte[] export = ReportFileUtil.export(exportDtoList, ReportFileConfigEnum.LEDGER_FILE_EXPORT);
    //     String html = "敬启者:\n" +
    //             "您好!\n" +
    //             "截至" + dto.getEndTime() +"，运营无锡收到的KYC、SAC文档清单详见附件，仅供参考\n" +
    //             "如需更新或查询，请联系运营管理总部股行运营岗。\n" +
    //             "附件:材料清单EXCEL(2个sheet页，1为产品，2个机构)";
    //     List<String> recList = Lists.newArrayList("gy_mo@glsc.com.cn", "twj@glsc.com.cn");
    //     mailService.sendMail()
    //
    // }
}